package com.example.rwq_test.niuke.stack;

import java.util.HashSet;
import java.util.Set;

/**
 * TODO note
 *
 * @author renweiqiang
 * @version 1.0.0
 * @createTime 2023/12/22
 */
public class ArrayOccurOneTimes {
    private static final Set<Integer> record = new HashSet<>();

    public static void main(String[] args) {
        int[] arr = {2,23,4,2,2,3,4,2,4,2,21};
        doHandleArr2(arr);
        for (Integer i : record) {
            System.out.println(i);
        }
    }

    private static void doHandleArr(int[] arr) {
        Set<Integer> temp = new HashSet<>();
        for (int i = 0; i < arr.length; i++) {
            int val = arr[i];
            if (temp.contains(val)) {
                continue;
            }
            if (record.contains(val)) {
                record.remove(val);
                temp.add(val);
            } else {
                record.add(val);
            }
        }
    }

    private static void doHandleArr2(int[] arr) {
        Set<Integer> temp = new HashSet<>();
        for (int i = 0; i < arr.length; i++) {
            int val = arr[i];
            if (temp.contains(val)) {
                record.remove(val);
            } else {
                record.add(val);
                temp.add(val);
            }
        }
    }
}
